package com.xrs.xrseducation.user.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xrs.xrseducation.user.entity.User;
import com.xrs.xrseducation.user.jsonUtils.UserJson;
import com.xrs.xrseducation.user.mapper.UserMapper;
import com.xrs.xrseducation.user.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-09-21
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserJson queryall(Integer page,Integer limit) {
        UserJson userJson=new UserJson();
        IPage<User> page1=new Page<>(page,limit);
        IPage iPage=userMapper.selectPage(page1,null);
        List<User> list=iPage.getRecords();
        if(list.size()>0){
            userJson.setCode(0);
            userJson.setMsg("查询成功");
            userJson.setCount(Integer.valueOf(String.valueOf(page1.getTotal())));
            userJson.setData(list);
        }else{
            userJson.setCode(1);
            userJson.setMsg("无数据");
        }
        return userJson;
    }

    @Override
    public UserJson add(User user) {
        UserJson userJson=new UserJson();
        int b=userMapper.insert(user);
        if(b>0){
            userJson.setCode(0);
        }else{
            userJson.setCode(1);
        }
        return userJson;
    }
}
